package db

import (
	"gorm.io/gorm/schema"
	"log"
	"os"

	"gorm.io/gorm"
	"gorm.io/gorm/logger"
)

func Open(c Config, options ...GORMOption) (*gorm.DB, error) {
	dialer := c.dialector()
	return gorm.Open(dialer, applyOptions(&gorm.Config{
		NamingStrategy: Namer{Namer: schema.NamingStrategy{SingularTable: true}},
		Logger:         logger.New(log.New(os.Stdout, "[GORM]", log.LstdFlags), c.Logger.Build()),
	}, options...))

}
